class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :set_locale
  helper_method :current_user
  
  rescue_from CanCan::AccessDenied do |exception|
    flash[:error] = "Acceso denegado."
    redirect_to root_url
  end

  def set_locale
    I18n.locale = params[:locale] || I18n.default_locale
  end
  
  private
  def current_user
    @current_user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token]
  end
end
